define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'customer/index' + location.search,
                    add_url: 'customer/add',
                    edit_url: 'customer/edit',
                    del_url: 'customer/del',
                    multi_url: 'customer/multi',
                    import_url: 'customer/import',
                    table: 'customer',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'user_id', title: __('User_id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'contact_name', title: __('Contact_name'), operate: 'LIKE'},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2')}, formatter: Table.api.formatter.normal},
                        {field: 'id_card', title: __('Id_card'), operate: 'LIKE'},
                        {field: 'card_image', title: __('Card_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'email', title: __('Email'), operate: 'LIKE'},
                        {field: 'sex', title: __('Sex'), searchList: {"1":__('Sex 1'),"2":__('Sex 2')}, formatter: Table.api.formatter.normal},
                        {field: 'backup_mobile', title: __('Backup_mobile'), operate: 'LIKE'},
                        {field: 'card_address', title: __('Card_address'), operate: 'LIKE'},
                        {field: 'job', title: __('Job'), operate: 'LIKE'},
                        {field: 'company_name', title: __('Company_name'), operate: 'LIKE'},
                        {field: 'company_address', title: __('Company_address'), operate: 'LIKE'},
                        {field: 'car_no', title: __('Car_no'), operate: 'LIKE'},
                        {field: 'ji_name', title: __('Ji_name'), operate: 'LIKE'},
                        {field: 'ji_mobile', title: __('Ji_mobile'), operate: 'LIKE'},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'delete_time', title: __('Delete_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'is_black', title: __('Is_black'), searchList: {"0":__('Is_black 0'),"1":__('Is_black 1')}, formatter: Table.api.formatter.normal},
                        // {field: 'black_type', title: __('Black_type')},
                        {field: 'black_reason', title: __('Black_reason'), operate: 'LIKE'},
                        {field: 'remark', title: __('Remark'), operate: 'LIKE'},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            // 类型字段变化时触发
            $(document).on('change', '#c-type', function () {
                var type = $(this).val();
                // 示例1：如果类型是1，显示"价格"字段，隐藏"分类"字段
                if (type == 1) {
                    $('.types').hide(); // 隐藏分类行
                }
                // 示例2：如果类型是2，显示"分类"和"URL"字段，隐藏"价格"字段
                else if (type == 2) {
                    $('.types').show(); // 隐藏分类行
                }
            });
            $('.types').hide(); // 隐藏分类行
            Controller.api.bindevent();
        },
        edit: function () {
            // 类型字段变化时触发
            $(document).on('change', '#c-type', function () {
                var type = $(this).val();
                // 示例1：如果类型是1，显示"价格"字段，隐藏"分类"字段
                if (type == 1) {
                    $('.types').hide(); // 隐藏分类行
                }
                // 示例2：如果类型是2，显示"分类"和"URL"字段，隐藏"价格"字段
                else if (type == 2) {
                    $('.types').show(); // 隐藏分类行
                }
            });
            $('.types').hide(); // 隐藏分类行
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
